<?php
class WebUser extends CWebUser {

    // some code here

    public function loginRequired() {
        $app=Yii::app();
        $request=$app->getRequest();

        if(!$request->getIsAjaxRequest())
            $this->setReturnUrl($request->hostInfo.'/'.$request->pathInfo);

        if(($url=$this->loginUrl)!==null) {
            if(is_array($url)) {
                $route=isset($url[0]) ? $url[0] : $app->defaultController;
                $url=$app->createUrl($route,array_splice($url,1));
            }
            $request->redirect($url);
        }
        else
            throw new CHttpException(403,Yii::t('yii','Login Required'));
    }

}

?>